#ifndef __kvdb_h__
#define __kvdb_h__

#include <stdint.h>
#include <stdbool.h>

// 数据库实例
struct kvdb_s;
// 结构体指针, 指向 数据库实例
typedef struct kvdb_s *kvdb_t;

// 迭代器
struct cursor_s;
typedef struct cursor_s *cursor_t;

// 打开数据库 完成数据初始化工作
kvdb_t kvdb_open(char *name);

int kvdb_close(kvdb_t db);

// 返回 int
int kvdb_get(kvdb_t db, uint64_t k, uint64_t *v);

// 采用v变量复制
int kvdb_put(kvdb_t db, uint64_t k, uint64_t v);

int kvdb_del(kvdb_t db, uint64_t k);

// 开启范围查询
cursor_t kvdb_open_cursor(kvdb_t db, uint64_t start_key, uint64_t end_key);

int kvdb_get_next(kvdb_t db, cursor_t cs, uint64_t *k, uint64_t *v);

int kvdb_del_next(kvdb_t db, cursor_t cs, uint64_t *k, uint64_t *v);

void kvdb_close_cursor(kvdb_t db, cursor_t cs);

// 持久化
void kvdb_dump(kvdb_t d);

#endif 

